#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define endl '\n'
using namespace std;
const int N = 1e4 + 10;

int a[N];
int pre[N];

bool is_prime(int n){
	if(n == 1 || n == 0) return false;
	for(int i = 2; i * i <= n; i++){
		if(n % i == 0) return false;
	}
	return true;
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		if(is_prime(a[i])) pre[i] = pre[i - 1] + 1;
		else pre[i] = pre[i - 1];
	}
	int q;
	scanf("%d", &q);
	while(q--){
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", pre[r] - pre[l - 1]);
	}
	return 0;
}